<?php
namespace Home\Controller;
use Think\Controller;
		/**
		 * 运营商控制器
		 */
		class YunyingController extends HomeController{
			/**
			 * 运营商列表
			 */
			public  function index(){
		/*		$page=I('get.page','1','strip_tags');
			$pagearr= getPageArr($page,C('PAGESIZE'),$count);*/

		        $count=M('yunying_user')->count();
		        $page=I('get.page','1','strip_tags');
		        $pagearr= getPageArr($page,C('PAGESIZE'),$count);

				$re=M('yunying_user')->limit($pagearr['start'],$pagearr['pagesize'])->select();
				$this->assign('re',$re);
				$this->assign('pagearr',$pagearr);
				$this->display('index');

			}

			/**
			 * 运营商的添加
			 */
			public function add(){
				if(IS_POST){
					$_POST['pass']=md5($_POST['password']);
					$re=M('yunying_user')->add($_POST);
					if($re>0){
						$this->redirect("Yunying/index");
					}

				}else{
					$this->display();
				}
			}

			/**
			 * 检测运营商的唯一性
			 */


		public function weiyi(){
			$where['yname']=$_GET['yname'];
			$yid=M('yunying_user')->where($where)->getFiled("yid");
			if(is_null($yid)){
				$data = array('status'=>200,'code'=>'success','info'=>'无效的手机号');
					echo json_encode($data);
				}else{
					$data = array('status'=>404,'code'=>'error','info'=>'该运营商已经存在');
					echo json_encode($data);
				}
		}


		/**
		 * 运营商冻结
		 */
		public function Frozen(){
		$where['yid']=$_GET['id'];
		$map[isdel]='1';
		$re=M('yunying_user')->where($where)->save($map);
			
		}


	/**
	 * 运营商编辑
	 */
	public function edit(){
		if(IS_POST){
			$where['yid']=$_GET['id'];
			$yun=M('yunying_user');
			$yun->create();
			$yun->yname=I('post.yname','','strip_tags');
			$yun->companyname=I('post.companyname','','strip_tags');
			$yun->connectname=I('post.connectname','strip_tags','tags');
			$yun->mobile=I('post.mobile','','strip_tags');
			$yun->qq=I('post.qq','','strip_tags');
			$yun->area=I('post.area','','strip_tags');
			$yun->address=I('post.address','','strip_tags');
			$pass=I('post.pass','','strip_tags');
			if (!empty($pass))
			{
				
				$yun->password=md5($pass);

			}
			
			$result=$yun->where($where)->save();
			if($result !== false){
				
				echo "<script>alert('修改成功');location.href='/admin.php/Home/Yunying/index'</script>";
				
			}else
			{
				echo "<script>alert('请重新修改');location.href='/admin.php/Home/Yunying/index'</script>";
			}

			}else{
				$where['yid']=$_GET['id'];
				$re=M('yunying_user')->where($where)->find();
				$this->assign('re',$re);
				$this->display();
			}
		}


		/**
		 * 运营商下的加盟商
		 */
		public function minute(){
		$where['founder']=$_GET['id'];
		$count=M('shop_user')->where($where)->count();
		$page=I('get.page','1','strip_tags');
		$pagearr= getPageArr($page,C('PAGESIZE'),$count);
		$re=M('shop_user')->where($where)->limit($pagearr['start'],$pagearr['pagesize'])->select();
		$this->assign('re',$re)->assign('pagearr',$pagearr);
		$this->display();




		}
		}